package com.elinkway.infinitemovies.ui.activity.play;

import android.annotation.SuppressLint;
import android.content.Intent;

import com.elinkway.infinitemovies.application.MoviesApplication;
import com.elinkway.infinitemovies.utils.DialogUtil;
import com.elinkway.infinitemovies.utils.LogUtils;
import com.elinkway.infinitemovies.utils.NetWorkTypeUtils;
import com.elinkway.infinitemovies.utils.ToastUtil;
import com.le123.ysdq.R;

/**
 * @author dyf
 */
@SuppressLint("NewApi")
public class HandlerInterfaceImpl implements HandlerInterface {

	private static final String TAG = "HandlerInterfaceImpl";

	public int checkNetwork(PlayActivitySelfOwn videoPlayer, Intent intent,PlayMediaController playMediaController, DialogUtil dialogUtil,
			int priorNetType) {
		String action = intent.getAction();
		int nowNetType = 4;// 无效网络
		if (null == action || "".equals(action) || videoPlayer == null)
			return nowNetType;
		if (action.equals(PlayerUtils.CONNECTIVTY_CHANGE)) {
			int netType = NetWorkTypeUtils.getNetType();
			LogUtils.e(TAG, "---------------netType-------------" + netType);

			if (NetWorkTypeUtils.NETTYPE_NO == netType) {
				if (0 != priorNetType) {
					ToastUtil.showShortToast(MoviesApplication.getInstance(),
							R.string.nonet_tip);
				}
				nowNetType = 0;
			} else if (NetWorkTypeUtils.NETTYPE_2G == netType
					|| NetWorkTypeUtils.NETTYPE_3G == netType) {
				if (!videoPlayer.getWifiTo3GFlag()) {// 用户没有选择在3g模式下观看
					if (!playMediaController.ismIsPause()) {
					    playMediaController.setmIsPause(true);
						playMediaController.onPause();
					}
					String tips = String.format("%s<font color=#3599f8>%s</font>%s<font color=#3599f8>%s</font>",
							"您正在使用",
							"移动网络",
							",观看视频将产生",
							"流量费用");
					dialogUtil.showFullScreenDialog(playMediaController, tips);
				}
				nowNetType = 1;
			} else if (NetWorkTypeUtils.NETTYPE_WIFI == netType) {
				if (2 != priorNetType) {
					ToastUtil.showShortToast(MoviesApplication.getInstance(),
							R.string.wifi_tip);
				}
				nowNetType = 2;
				// ToastUtil.showShortToast(MoviesApplication.getInstance(),
				// R.string.wifi_tip);
			}
		}
		return nowNetType;
	}

    @Override
    public int checkNetwork(PlayActivityLive livePlayer, Intent intent,
            PlayLiveController liveController, DialogUtil dialogUtil, int priorNetType) {
        String action = intent.getAction();
        int nowNetType = 4;// 无效网络
        if (null == action || "".equals(action) || livePlayer == null)
            return nowNetType;
        if (action.equals(PlayerUtils.CONNECTIVTY_CHANGE)) {
            int netType = NetWorkTypeUtils.getNetType();
            LogUtils.e(TAG, "---------------netType-------------" + netType);
            if (NetWorkTypeUtils.NETTYPE_NO == netType) {
                if (0 != priorNetType) {
                    ToastUtil.showShortToast(MoviesApplication.getInstance(), R.string.nonet_tip);
                }
                nowNetType = 0;
            } else if (NetWorkTypeUtils.NETTYPE_2G == netType
                    || NetWorkTypeUtils.NETTYPE_3G == netType) {
                if (!livePlayer.getWifiTo3GFlag()) {// 用户没有选择在3g模式下观看
//                    if (liveController.isVideoPlaying()) {
                        liveController.isShow3GDialog = true;
                        liveController.onPause();
//                    }
                    dialogUtil.showPlayerCheckNetDialog(liveController, false, false,
                            R.string.moblie_net_tip);
                }
                nowNetType = 1;
            } else if (NetWorkTypeUtils.NETTYPE_WIFI == netType) {
                if (2 != priorNetType) {
                    ToastUtil.showShortToast(MoviesApplication.getInstance(), R.string.wifi_tip);
                }
                nowNetType = 2;
                // ToastUtil.showShortToast(MoviesApplication.getInstance(),
                // R.string.wifi_tip);
            }
        }
        return nowNetType;
    }

}
